package com.luomo.java.juc.util;

import java.util.concurrent.CountDownLatch;

/**
 * @author LiuMei
 * @date 2021-04-07.
 */
public class CountDownLatchDemo {

    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {
            new Thread(() -> {
                String desc = CountryEnum.getDescByCode(Integer.valueOf(Thread.currentThread().getName()));
                System.out.println(desc + "国，被灭");
                countDownLatch.countDown();
            }, i + 1 + "").start();
        }
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("秦帝国，一统华夏");
    }

    private static void lockDoor() {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "\t走了");
                countDownLatch.countDown();
                System.out.println("--------");
            }, i + 1 + "").start();
        }
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("班长锁门");
    }


}
